<?php
ob_start();
session_start();
$_SESSION['aberta'] = true;
?>

<div id="content">
    <h3 style="padding-bottom:20px">Preencha o formulário completo:</h3>
    <form action="confirmaVenda.php" method="post">
        <table width="350" align="center" cellpadding="2" cellspacing="2">
            <tr>
                <td width="167" align="center">Funcionario </td>
                <td width="167">
                    <input type="text" value="<?php echo $_SESSION['usuarioNome']; ?>" disabled name="funcionario">
                </td>
            </tr>
            <tr>
                <td align="center">Data da Compra</td>
                <td>
                    <input type="text" readonly value="<?php
date_default_timezone_set('America/Campo_Grande');
echo date('d-m-Y H:i:s');
?>" name="data" id="dataID">
                </td>
            </tr>
            <tr>
                <td align="center" height="50px" colspan="2">Medicamentos 
                </td>
            </tr>
        </table>
        <?php
        include("../model/medicamento.php");
        $medicamento = Medicamento::FindAll();
        if (mysql_num_rows($medicamento) > 0) {
            echo'<table class="tabelaGrid" align="center">';
            echo "<tr class='menuGrid'><td class='menuGrid'>";
            echo "</td><td class='menuGrid'>Nome</td><td class='menuGrid'>Quantidade</td><td class='menuGrid'>Em estoque</td></tr>";
            $i = 0;
            while ($row = mysql_fetch_assoc($medicamento)) {
                echo "<tr><td>";
                echo "<input type='checkbox' name='Med" . $row['id'] . "'>";
                echo "</td><td>";
                echo $row['nome'];
                echo "</td><td>";
                echo "<input type='text' size='4' name='" . $row['id'] . "' />";
                echo "</td><td>";
                echo "<input type='text' disabled name='estoque" . $i . "' value='" . $row['quantidade'] . "' size='4' />";
                echo "</td></tr>";
                $i++;
            }
            echo '</table>';
        } else {
            echo "<h4> Nenhum medicamento cadastrado! </h4>";
        }
        ?>

        <br/>
        <input type="submit" <?php if (mysql_num_rows($medicamento) == 0) echo "disabled"; ?> value="Continuar">
        <input type="reset" value="Limpar">        
    </form>
</div>

<?php
$pagemaincontent = ob_get_contents();
ob_end_clean();
$pagetitle = "Cadastrar Funcionário";
include("master.php");
?>